char sensorArray[15];
sensorArray[0] = 'V';

// this program switches between ADC pins on ATMega324
// Cassi Latino 2/27/2012

#define IR_Threshold 240
#define Ultra_Threshold 64
#define Current_Threshold 4 //NEEDS VALUE CHANGED TO PROPER VALUE AFTER JON DETERMINES IT (1/364 of voltage then divided by the resistor to ground on board gives current value)

void init_adc(void) {
	ADCSRA |= 1 << ADPS2;   //bit to set for micro-controller for ADC at 1MHz
	ADMUX  |= 1 << REFS0 | 1 << REFS1;	//enable internal voltage reference
	ADCSRA |= 1 << ADEN;    //enable ADC
	ADCSRA |= 1 << ADSC;    // establish single conversion
}

char read_sensor(){
	unsigned int adcValue, theLow, sensor;
    char warning = 0;
    
    for(int i=3;i<8;i++){
        ADCSRA |= 1 << ADSC;	// establish single conversion
        ADMUX &+ ~0xF;          // clear shosen channel
        ADMUX |= i;             // select channel for conversion
        
        while(ADSC==1);
        theLow = ADCL;
        adcValue = ADCH<<8 | theLow;
        
        switch(i){
            case 3;
                sensorArray[1] = ADCH;
                sensorArray[2] = ADCL;
                if(adcValue >= IR_Threshold) 
                    warning = 1;
                break;
            case 4:
                sensorArray[3] = ADCH;
                sensorArray[4] = ADCL;
                if(adcValue >= Ultra_Threshold) 
                    warning = 1;
                break;
            case 5:
                sensorArray[5] = ADCH;
                sensorArray[6] = ADCL;
                if(adcValue >= IR_Threshold)
                    warning = 1;
                break;
            case 6:
                sensorArray[7] = ADCH;
                sensorArray[8] = ADCL;
                if(adcValue >= Current_Threshold) 
                    warning = 1;
                break;
            case 7:
                sensorArray[9] = ADCH;
                sensorArray[10] = ADCL;
                if(adcValue >= Current_Threshold) 
                    warning = 1;
                break;
            default:
                warning = 0;
                break;
        } //end switch statement for saving readings
    } //end for loop to select ADC channels and read
    return warning;
} // end char read_sensor()